#[macro_use]
extern crate rocket;
extern crate diesel;
extern crate rocket_sync_db_pools;

mod auth;
mod db;
mod mapper;
mod models;
mod router;
mod schema;

use db::DbConn;
use router::*;

#[rocket::main]
async fn main() {
  // let server = rocket::build().mount("/", routes!(hello));
  let server = rocket::build()
    .mount(
      "/",
      routes![
        hello,
        get_todo,
        view_todo,
        create_todo,
        update_todo,
        delete_todo
      ],
    )
    .register("/", catchers![not_found])
    .attach(DbConn::fairing());

  server.launch().await.unwrap();
}

// 0.5 后可以如下写法
// #[launch]
// fn rocket() -> _ {
//   rocket::build().mount("/hello", routes![hello])
// }

// cargo install diesel_cli
// https://diesel.rs/guides/getting-started.html
// cargo install diesel_cli --no-default-features --features sqlite

// diesel setup --database-url ./database.sqlite

// diesel migration list

// diesel migration generate create_todo

// diesel migration list --database-url=database.sqlite

// diesel migration run --database-url=database.sqlite

// diesel migration list --database-url=database.sqlite

// diesel migration revert --database-url=database.sqlite

// diesel migration run --database-url=database.sqlite
